package com.jobpass.common.model;

import com.alibaba.excel.annotation.ExcelProperty;
import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.jobpass.common.converter.LocalDateTimeConverter;
import com.jobpass.common.converter.SexConverter;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import javax.validation.constraints.*;
import java.io.Serializable;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Date;


@Data
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = false)
@ApiModel(value="Student对象", description="")
public class Student implements Serializable {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "学生id")
    @TableId(value = "id", type = IdType.AUTO)
    private Long id;

    @ExcelProperty("学号")
    @NotBlank(message = "学号不能为空")
    @ApiModelProperty(value = "学生学号")
    private String number;

    @NotBlank(message = "密码不能为空")
    @Size(max = 16,min = 8,message = "密码长度为8-16字符")
    @ApiModelProperty(value = "密码（学号后四位）")
    private String password;

    @ExcelProperty("姓名")
    @NotBlank(message = "姓名不能为空")
    @ApiModelProperty(value = "学生姓名")
    private String name;

    @ExcelProperty(value = "性别", converter = SexConverter.class)
    @Max(value = 1,message = "性别格式错误")
    @ApiModelProperty(value = "学生性别（0为男，1为女）")
    private Integer sex;


    @ExcelProperty(value = "年龄")
    @ApiModelProperty(value = "学生年龄（出生日期）")
    private Integer age;

    @ExcelProperty("身份证号")
    @Pattern(regexp = "(^[1-9]\\\\d{5}(18|19|20)\\\\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\\\\d{3}[0-9Xx]$)|(^[1-9]\\\\d{5}\\\\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\\\\d{3}$)",
            message = "身份证号错误")
    @ApiModelProperty(value = "学生身份证号")
    private String identityCard;

    @ExcelProperty("电话")
    @Pattern(regexp = "^(13[0-9]|14[5|7]|15[0|1|2|3|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\\d{8}$",
            message = "电话错误")
    @ApiModelProperty(value = "学生电话")
    private String tel;

    @ExcelProperty("邮箱")
    @Email(message = "邮箱格式不正确")
    @ApiModelProperty(value = "学生邮箱")
    private String mailbox;

    @ApiModelProperty(value = "学生头像")
    private String portrait;

    @ApiModelProperty(value = "学生个人简历")
    private String resume;

    @ExcelProperty(value = "入学时间",converter = LocalDateTimeConverter.class)
    @Pattern(regexp = "^\\d{4}-\\d{1,2}-\\d{1,2}",message = "时间错误")
    @ApiModelProperty(value = "学生入学时间")
    private LocalDateTime enrolTime;

    @ApiModelProperty(value = "学生班级id")
    private Long gradeId;

    @ApiModelProperty(value = "创建时间")
    @TableField(fill = FieldFill.INSERT)
    private Date creatTime;

    @ApiModelProperty(value = "修改时间")
    @TableField(fill = FieldFill.INSERT_UPDATE)
    private Date updateTime;

    //  ========= 以下字段不是数据库字段，方便使用 ===========
    @ExcelProperty("院系")
    @TableField(exist = false)
    @JsonIgnore
    private String facultyName;

    @ExcelProperty("专业")
    @TableField(exist = false)
    private String majorName;

    @ExcelProperty("班级")
    @TableField(exist = false)
    private String gradeName;

}
